package com.example.hospital.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospital.dto.PrescriptionQuery;
import com.example.hospital.entity.Prescription;
import com.example.hospital.service.PrescriptionService;
import com.example.hospital.mapper.PrescriptionMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Oreki
 * @description 针对表【prescription】的数据库操作Service实现
 * @createDate 2024-12-27 16:53:20
 */
@Service
public class PrescriptionServiceImpl extends ServiceImpl<PrescriptionMapper, Prescription>
        implements PrescriptionService {

    @Override
    public List<Prescription> listPrescriptions(PrescriptionQuery prescriptionQuery) {
        if (prescriptionQuery == null) {
            return this.list();
        }
        Integer patientId = prescriptionQuery.getPatientId();
        Integer doctorId = prescriptionQuery.getDoctorId();
        Integer medicalrecordId = prescriptionQuery.getMedicalrecordId();
        String status = prescriptionQuery.getStatus();
        String startDate = prescriptionQuery.getStartDate();
        String endDate = prescriptionQuery.getEndDate();
        String medications = prescriptionQuery.getMedications();
        return this.lambdaQuery()
                .eq(patientId != null, Prescription::getPatientId, patientId)
                .eq(doctorId != null, Prescription::getDoctorId, doctorId)
                .eq(medicalrecordId != null, Prescription::getMedicalrecordId, medicalrecordId)
                .eq(StrUtil.isNotEmpty(status), Prescription::getStatus, status)
                .ge(StrUtil.isNotEmpty(startDate), Prescription::getPrescriptionDate, startDate)
                .le(StrUtil.isNotEmpty(endDate), Prescription::getPrescriptionDate, endDate)
                .like(StrUtil.isNotEmpty(medications), Prescription::getMedications, medications)
                .list();
    }
}




